//
//  SCPresentView.m
//  Smart
//
//  Created by Hayder on 2022/11/4.
//

#import "HHPresentView.h"
#import "HHGlobalDefine.h"
@interface HHPresentView()

@end

@implementation HHPresentView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        UIView *tapView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, HH_SCREEN_WIDTH, 200)];
        tapView.backgroundColor = HHRGBA(0, 0, 0, 0.5);
        [tapView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidden)]];
        [self addSubview:tapView];
        self.tapView = tapView;
        
        UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(0, tapView.bottom - 20, HH_SCREEN_WIDTH, HH_SCREEN_HEIGHT)];
        blankView.backgroundColor = UIColor.whiteColor;
        [self addSubview:blankView];
        self.contentView = blankView;
        
        self.y = HH_SCREEN_HEIGHT;
    }
    
    return self;
}

/**内容上加圆角的View*/
- (void)addCornerRadiusView
{
    [self.contentView cornerRadius:10];
}
/**
 点击view的高度
 */
- (void)setTapViewHeight:(CGFloat)tapViewHeight
{
    self.tapView.height = tapViewHeight;
    self.contentView.top = self.tapView.bottom;
    self.contentView.height = HH_SCREEN_HEIGHT - tapViewHeight;
}

- (void)show
{
    [UIView animateWithDuration:0.25 animations:^{
        self.y = 0;
    } completion:^(BOOL finished) {
        self.tapView.alpha = 1;
    }];
}

- (void)hidden
{
    [UIView animateWithDuration:0.1 animations:^{
        self.tapView.alpha = 0;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.25 animations:^{
            self.y = HH_SCREEN_HEIGHT;
        }];
    }];
}


@end
